package com.sphd.emanu.fragment.data;


import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sphd.emanu.R;
import com.sphd.emanu.activity.sale.Salectivity;
import com.sphd.emanu.activity.todaysale.TodaysaleActivity;
import com.sphd.emanu.activity.topmanagers.TopmanagersActivity;
import com.sphd.emanu.activity.topup.TopUpTodayActivity;
import com.sphd.emanu.activity.topupmonth.TopupmonthActivity;
import com.sphd.emanu.config.Constant;
import com.sphd.emanu.mvp.MVPBaseFragment;
import com.sphd.emanu.pojo.RespSale;
import com.sphd.emanu.pojo.login.User;
import com.wzutils.TimeUtils;

import java.util.Date;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;


/**
 * 数据页面
 *
 * @Author Hu
 * @Time 2017/4/1 -- 15:06.
 * @Email 87683202@qq.com
 */
public class DataFragment extends MVPBaseFragment<DataContract.View, DataPresenter> implements DataContract.View {


    Intent intent;
    Bundle bundle;
    @BindView(R.id.res_name)
    TextView resName;
    @BindView(R.id.res_serach)
    ImageView resSerach;
    @BindView(R.id.res_all_money)
    TextView resAllMoney;
    @BindView(R.id.res_month_sale)
    TextView resMonthSale;
    @BindView(R.id.layout_res_month_sale)
    LinearLayout layoutResMonthSale;
    @BindView(R.id.res_day_topup)
    TextView resDayTopup;
    @BindView(R.id.layout_res_day_topup)
    LinearLayout layoutResDayTopup;
    @BindView(R.id.res_month_topup)
    TextView resMonthTopup;
    @BindView(R.id.layout_res_month_topup)
    LinearLayout layoutResMonthTopup;
    @BindView(R.id.res_admin_manage)
    TextView resAdminManage;
    @BindView(R.id.res_add_new)
    TextView resAddNew;
    Unbinder unbinder;
    private static final String TAG = "DataFragment";
    User user;
    @BindView(R.id.today_time)
    TextView todayTime;


    @Override
    protected int getLayoutId() {
        return R.layout.fragment_data;
    }

    @Override
    protected void initView() {
        unbinder = ButterKnife.bind(this, rootView);
        intent = new Intent();
        bundle = getArguments();
        user = (User) bundle.getSerializable(Constant.USER_ENTITY);
        resName.setText(user.getOrg().getName());
        //判断身份 如果是超管则显示高管管理
        if (user.getRoleid().equals("1")) {
            resAdminManage.setVisibility(View.VISIBLE);
        }

        setUserVisibleHint(true);
    }

    @Override
    protected void initData() {
        showProgressDialog();
        mPresenter.aleIndex(user.getOid());
    }


    @OnClick({R.id.res_serach, R.id.res_all_money, R.id.layout_res_month_sale, R.id.layout_res_day_topup, R.id.layout_res_month_topup, R.id.res_admin_manage, R.id.res_add_new})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.res_serach:
                Log.e("--------", "---------");
                //查询
                intent.setClass(context, Salectivity.class);
                bundle.putInt(Constant.TYPE, 0);
                break;
            case R.id.res_all_money:
                //日销售
                intent.setClass(context, TodaysaleActivity.class);
                bundle.putString(Constant.DAY_SALE, null);
                bundle.putInt(Constant.TYPE, 1);
                break;
            case R.id.layout_res_month_sale:
                //月销售
                intent.setClass(context, Salectivity.class);
                bundle.putInt(Constant.TYPE, 1);
                Log.e("--------", "---------");
                break;
            case R.id.layout_res_day_topup:
                //今日充值
                intent.setClass(context, TopUpTodayActivity.class);
                bundle.putInt(Constant.TYPE, 0);
                Log.e("--------", "---------");
                break;
            case R.id.layout_res_month_topup:
                //本月充值
                intent.setClass(context, TopupmonthActivity.class);
                bundle.putInt(Constant.TYPE, 1);
                break;
            case R.id.res_admin_manage:
                //高管管理
                intent.setClass(context, TopmanagersActivity.class);
                break;
            case R.id.res_add_new:
                break;

        }
        intent.putExtras(bundle);
        startActivity(intent);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }


    @Override
    public void recBean(RespSale respSale) {
        dissProgressDialog();
        todayTime.setText("今日销售额"+"\t"+TimeUtils.dateToString(respSale.getDate()==null?new Date():respSale.getDate(),TimeUtils.YEAR_MONTH_DAY));
        resAllMoney.setText(respSale.getDaySale().toString());
        resMonthSale.setText(respSale.getMonthSale().toString());
        resDayTopup.setText(respSale.getDayDeposit().toString());
        resMonthTopup.setText(respSale.getMonthDeposit().toString());
    }


}
